Hello, young web designer! In this tutorial, we're going to learn about HTML file and link paths. File paths help you tell the browser where to find resources, like images, other web pages, and stylesheets. They also help you link to other websites. Let's get started!
Absolute paths: These paths include the complete URL of a resource, like "https://example.com/images/pic.jpg". Absolute paths are used when linking to resources on other websites or external files.
Relative paths: These paths are related to the current file's location. Relative paths are used when linking to files within the same website or folder.
To link to an image in the same folder as your HTML file, use the image file name: <img src="image.jpg" alt="An example image">
To link to an image in a folder named "images" that is inside the same folder as your HTML file, use the folder name and the image file name: <img src="images/image.jpg" alt="An example image">
To link to an image in the parent folder (one level up) of your HTML file, use ../
followed by the image file name: <img src="../image.jpg" alt="An example image">
<a>
(anchor) element with the href
attribute, which specifies the target URL. Here's how to create links using absolute and relative paths:Link to an external website using an absolute path: <a href="https://example.com">Visit Example.com</a>
Link to another page within your website using a relative path: <a href="about.html">About</a>
Step 1: Open the HTML file you created in the previous tutorial or create a new one.
Step 2: Add an image to your web page using a relative path. Make sure the image file is in the same folder as your HTML file or in a subfolder.
Step 3: Create a hyperlink to another web page on your site. If you don't have another page yet, create a new HTML file (like "about.html") and add some content to it.
Step 4: Create a hyperlink to an external website using an absolute path.
Step 5: Save your file and open it in a web browser to see the changes to your web page!
Understanding file and link paths is essential for creating well-structured websites and linking to various resources. Keep practicing, and soon you'll be a pro at using both absolute and relative paths in your web designs!